{include file="public/nheader"}
<style type="text/css">
    #lay-tableList {
        height: auto;
    }

    .layui-table-view .layui-table[lay-size=lg] .layui-table-cell {
        height: auto;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="status" lay-verify="">
                                <option value="">状态</option>
                                <option value="1" {if !empty(input('get.status')) &&
                                    input('get.status')==1}selected{/if}>进行中</option>
                                <option value="2" {if !empty(input('get.status')) &&
                                    input('get.status')==2}selected{/if}>暂停</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="title" class="layui-input" type="text" placeholder="活动名称" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit>搜索</button>
                        <!-- // 打开添加页面 -->
                        <button class="layui-btn icon-btn" lay-maxmin="true" lay-open="" data-title="兑换码套餐"
                            data-area="60%,80%" data-url="/agent/promo_edit">添加套餐
                        </button>
                        <button class="layui-btn icon-btn" lay-maxmin="true" lay-open="" data-title="套餐分享码"
                            data-area="500px,550px" data-url="/agent/agent_qrcode">套餐分享码
                        </button>
                        <!-- // 打开添加页面 -->
                        <!-- <button class="layui-btn icon-btn  layui-btn-danger" lay-maxmin="true" lay-open=""
                            data-title="在线购买套餐" data-area="60%,80%" data-url="/agent/promo_edit2">添加在线购买套餐
                        </button> -->
                    </div>
                </div>
            </div>
        </div>
        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>
<!-- <a class="layui-table-text" data-title="生成兑换码" data-area="30%,40%" callback="edits" data-url="#adminforms"
    lay-event="edit" style="color:red">生成兑换码</a><br />
    <a class="layui-table-text" lay-open data-title="兑换码列表" data-area="90%,95%"
    data-url="/agent/keys?promoid={{d.id}}">兑换码列表</a>
<div class="layui-divider layui-divider-vertical"></div> -->
<script type="text/html" id="datagrid-toolbar">
</script>
<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    <!-- <a class="layui-table-text" lay-open data-title="查看二维码" data-area="400px,750px" data-url="/agent/promo_alert?id={{d.id}}" >二维码</a>
    <div class="layui-divider layui-divider-vertical"></div> -->
<a class="layui-table-text" lay-open data-title="券使用详情" data-area="80%,90%"
    data-url="/user/coupon?promo={{d.id}}">券使用详情</a>
<div class="layui-divider layui-divider-vertical"></div>
{{# if(d.type ==1){ }}

<a class="layui-table-text" lay-open data-title="编辑" data-area="60%,80%" data-url="/agent/promo_edit?id={{d.id}}">编辑</a>
<div class="layui-divider layui-divider-vertical"></div>
<a class="layui-table-text" lay-open data-title="申请记录" data-area="90%,95%"
    data-url="/agent/keys2?promoid={{d.id}}">申请记录</a>
{{# }if(d.type ==2) { }}
/*<a class="layui-table-text" lay-open data-title="编辑" data-area="60%,80%"
    data-url="/agent/promo_edit2?id={{d.id}}">编辑</a>
<div class="layui-divider layui-divider-vertical"></div>
<a class="layui-table-text" lay-open data-title="购买记录" data-area="90%,95%"
    data-url="/agent/keys?promoid={{d.id}}">购买记录</a>*/
{{# } }}

</script>
<script type="text/html" id="adminforms">
    <div class="layui-fluid layui-bg-white">
        <form class="layui-form layui-form-fixed" lay-filter="adminforms">
            <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>生成数量</label>
            <div class="layui-input-block">
                <input name="knumber" value="5"  placeholder="生成数量" type="number" class="layui-input" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item" style="color: red;">单次生成数量不能超过1000</div>
        <div class="layui-form-item">注:生成兑换码数量原兑换码会继续保留，仅在原基础上增加兑换码，如添加不成功或无反应，请查看兑换码列表是否已生成并关闭窗口刷新页面后再添加，避免重复添加</div>
        
        <div class="layui-footer layui-form-item layui-center ">
            <button class="layui-btn" lay-filter="submitPage" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closePageDialog" >取消</button>
        </div>
        </form>
    </div>
</script>
{include file="public/nfooter"}
<script>
    layui.use(['admin', 'layer', 'table', 'form'], function () {
        var admin = layui.admin;
        var layer = layui.layer;
        var table = layui.table;        // 表格
        var form = layui.form;
        admin.callback.edits = function (clickthis, colletction, config) {
            var tableThis = colletction.tableThis;
            // 监听权限提交
            form.on("submit(submitPage)", function (post) {

                // 获取用户id
                var pageThat = layui.$(this);
                pageThat.attr("disabled", true);
                // 开始POST提交数据
                post.field.id = tableThis.data.id;
                var index = layer.load(1); //换了种风格                
                layui.$.post("{:url('agent/promo_key')}", post.field, function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg);
                        // 关闭当前窗口
                        table.reload('lay-tableList');
                        layer.close(colletction.index);
                        layer.close(index);
                    }
                    else {
                        layer.error(res.msg);
                        layer.close(index);
                    }
                }, 'json');
                return false;
            })
        }        /*
         * 初始化表格
        */
        var isTable = table.render({
            elem: "#lay-tableList"
            , url: "{:url()}"
            , page: true
            , size: 'lg'
            , even: true

            , cols: [[
                { type: 'checkbox', width: 60 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                { field: 'title', width: 200, align: 'center', title: '套餐名称' },
                {
                    field: 'status', align: 'center', width: 120, templet: function (d) {
                        if (d.status == 1) {
                            return '开启';
                        }
                        return '结束';
                    }, title: '状态'
                },
                { field: 'money', width: 200, align: 'center', title: '售卖金额' },
                { align: 'center', width: 300, toolbar: '#tableBar', title: '操作' },
            ]]
        })
    })
</script>